package com.xinhua.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xinhua.domain.Ssmp;
import com.xinhua.service.IbookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

//@RestController
@RequestMapping("/ssmp")
public class SsmpContorller {

    @Autowired
    private IbookService ibookService;

    @GetMapping
    public List<Ssmp> getAll() {
        return ibookService.list();
    }

    //添加
    @PostMapping
    //通过请求体传json数据过来
    //RequestBody请求体参数  传递json格式的数据
    public Boolean save(@RequestBody Ssmp ssmp) throws IOException {
        return ibookService.save(ssmp);
    }

    @PutMapping
    public Boolean update(@RequestBody Ssmp ssmp) {
        return ibookService.updateById(ssmp);
    }

    @DeleteMapping("{id}")
    public Boolean delete(@PathVariable Integer id) {
        return ibookService.removeById(id);
    }

    @GetMapping("{id}")
    public Ssmp getById(@PathVariable Integer id) {
        return ibookService.getById(id);
    }

    @GetMapping("{currentPage}/{PageSize}")
//    PathVariable代表路径变量
    public IPage<Ssmp> Ipage(@PathVariable Integer currentPage, @PathVariable Integer PageSize) {
        return ibookService.getPage(currentPage, PageSize);
    }

}